﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Dynamic;
using Newtonsoft.Json;
using System.Data;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Collections;
using System.Web.Script.Serialization;
using ihongma.test.ServiceReference1;
using ihongma.Common;
namespace ihongma.test
{
    public partial class json : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //com.ihongma.www.addajaxCompletedEventArgs ds = new com.ihongma.www.addajaxCompletedEventArgs();
            //com.ihongma.www.ajax s = new com.ihongma.www.ajax();
            //com.ihongma.www.addajaxCompletedEventHandler h = new com.ihongma.www.addajaxCompletedEventHandler();
            //com.ihongma.www.addserver d = new com.ihongma.www.addserver();
            //d.
            //josnq("http://faxianla.com/mark/category.jsn?categoryId=2&offset=20&_=1350546694049");
            fortest();
        }
        public void fortest()
        {
            int i = 0;
        while(i<200)
        {
                josnq("http://faxianla.com/mark/category.jsn?categoryId=3&offset="+i.ToString()+"&_=1350546694049");
                i = i + 20;
            }
        }
        public class DictionaryDynamicObject : DynamicObject
        {
            public IDictionary<string, object> Values { get; private set; }

            protected DictionaryDynamicObject()
            {
                Values = new Dictionary<string, object>();
            }

            public override bool TrySetMember(SetMemberBinder binder, object value)
            {
                Values[binder.Name] = value;
                return true;
            }
        }
        public class DictionaryDynamicintObject : DynamicObject
        {
            public IDictionary<int, object> Values { get; private set; }

            protected DictionaryDynamicintObject()
            {
                Values = new Dictionary<int, object>();
            }

            
        }

        public void josnq(string str)
        {



            com.ihongma.www.addserver pic = new com.ihongma.www.addserver();
            string showhtml = HttpRequestHelper.GetPageSourceByUrl(str,"utf-8");
            JavaScriptSerializer jserializer = new JavaScriptSerializer();
            RootObject list=jserializer.Deserialize<RootObject>(showhtml);

            com.ihongma.www.photo model = new com.ihongma.www.photo();
           // ServiceReference1.photo_album blbum = new ServiceReference1.photo_album();
            com.ihongma.www.photo_attribute_value attribute = new com.ihongma.www.photo_attribute_value();
            foreach (var Kvalue in list.data)
            {
                Kvalue.title = Utils.DropHTML(Kvalue.title);
                model.channel_id = 10;
                model.title = Kvalue.title;
                model.category_id = 343;
                model.photo_no = Kvalue.id.ToString();
                model.market_price = Kvalue.image_height;
                model.sell_price = Kvalue.image_width;
                model.link_url =Kvalue.owner_url ;
                model.img_url = Kvalue.image_url;
                model.add_time =DateTime.Parse(Kvalue.created_at);
                model.content = "<img  src=\""+Kvalue.images.wood.url+"\">";
                model.seo_title =Kvalue.title ;
                model.seo_keywords = Kvalue.title+","+Kvalue.board_name;
                model.seo_description = Kvalue.title;
                model.sort_id = 99;
                model.click = 100;
                model.is_msg = 0;
                model.is_top = 0;
                model.is_red = 0;
                model.is_hot = 0;
                model.is_slide = 0;
                model.is_lock = 0;
               
                //保存相册

               List<com.ihongma.www.photo_album> ls=new List<com.ihongma.www.photo_album>();
               
                ls.Add(new ihongma.test.com.ihongma.www.photo_album { big_img = Kvalue.images.earth.url, small_img = Kvalue.images.earth.url });
                ls.Add(new ihongma.test.com.ihongma.www.photo_album { big_img = Kvalue.images.fire.url, small_img = Kvalue.images.fire.url });
                ls.Add(new ihongma.test.com.ihongma.www.photo_album { big_img = Kvalue.images.metal.url, small_img = Kvalue.images.metal.url });
                ls.Add(new ihongma.test.com.ihongma.www.photo_album { big_img = Kvalue.images.wood.url, small_img = Kvalue.images.wood.url });
                //扩展属性

                model.photo_albums = ls.ToArray();
                model.photo_attribute_values =null;
                pic.addpic(model, "s123456");
                Response.Write(Kvalue.title+"<br>");
                //ddlIOType.Items.Add(new ListItem(Kvalue.Key + " (" + Kvalue.Value+")",Kvalue.Key));
            }
        }
       
    }

}